package com.tfswue.zqm.service;

import com.tfswue.zqm.apis.UserClient;
import com.tfswue.zqm.entity.Order;
import com.tfswue.zqm.entity.User;
import com.tfswue.zqm.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserClient userClient;

    public Order getOrderById(Long id) {

        Order order = (Order) orderMapper.selectById(id);

        User user = userClient.getUserById(order.getUserId());
        order.setUser(user);
//        order.setUser(restTemplate.getForObject
//                ("http://user-server/api/users/" + order.getUserId(), User.class));
        return order;
    }
}